//
// Created by xiaoma on 1/28/21.
//

#ifndef HORSE_VM_ARRAYLIST_H
#define HORSE_VM_ARRAYLIST_H

template<typename T>
class ArrayList {
public:
    ArrayList(int n = 8);

    void add(T t);

    void insert(int index, T t);

    T get(int index) const { return _array[index]; }

    void set(int index, T t) { _array[index] = t; }

    int size() const { return _size; }

    int length() const { return _len; }

    T pop() { return _array[--_size]; }

private:
    T *_array;
    int _len;
    int _size;

    void expand();
};

#endif //HORSE_VM_ARRAYLIST_H
